require(['config'],()=>{
    require(['jquery','header','footer','floater'],()=>{
        let arr=JSON.parse(localStorage.getItem('key'))||[]
        $('#btn').on('click',()=>{
            let user=$('#username')[0].value
            let pass=$('#password')[0].value
            //非空验证
            if(!$('#username')[0].value||!$('#password')[0].value){
                alert('请输入账号或密码')
            }else{
                let res=$('#check')[0].checked
                let type=arr.some(item=>{return item.user==user})
                if(type){
                    alert('该用户已被注册')
                }else{
                    if(/^(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9~!@&%#_]{8,16}$/.test($('#password')[0].value)){
                        if(res){
                            let obj={
                                user,
                                pass,
                            }
                            arr.push(obj)
                            localStorage.setItem('key',JSON.stringify(arr))
                            if(confirm('注册成功，是否去登陆?')){
                                location.href = '/html/login.html'
                            }else{
                                return false
                            }
                        }else{
                            alert('请同意协议')
                        }
                    }else{
                        alert('密码格式错误!')
                    }
                }
            }
        })
    })
})